from rest_framework import serializers
from goods.models import SPUSpecification
from .spus import SPUSimpleSerializer


class SpecsSerializer(serializers.ModelSerializer):
    spu = serializers.StringRelatedField(read_only=True)
    spu_id = serializers.IntegerField()  ## 直接就能获得.外键的id可以直接获得

    class Meta:
        model = SPUSpecification
        fields = '__all__'
        # fields = ('id', 'name', 'spu_id', 'spu')


class SpecOptionSerializer(serializers.Serializer):
    id = serializers.IntegerField()
    value = serializers.CharField()


class SpecBySpuSerializer(serializers.Serializer):
    id = serializers.IntegerField()
    name = serializers.CharField()
    spu = serializers.StringRelatedField(read_only=True)
    spu_id = serializers.IntegerField()
    options = SpecOptionSerializer(many=True, read_only=True)



